home *** CD-ROM | disk | FTP | other *** search
/ Micromanía 90 / CDMM_90_1.ISO / Cycling Manager 2 / CyclingManager2Demo.exe / Disk1 / data1.cab / Game / DataCM2 / scripts / elements / captions.cnh < prev    next >
Encoding:
Text File  |  2002-05-10  |  2.5 KB  |  102 lines

  1. // captions.cnh
  2. // Standard captions
  3.  
  4. // -------------------------------------------------------------
  5. // Constructors
  6. // -------------------------------------------------------------
  7. // Init func Predeclaration
  8. func Gui_Component NewCaption(Menu_Material _pFont,szx _sxTxt);
  9. func Gui_Component NewCaptionAspectRatio(Menu_Material _pFont,szx _sxTxt,f32x _fFontSize);
  10.  
  11.  
  12. // Messages
  13. message Caption(szx _szTxt);
  14. // -------------------------------------------------------------
  15. // -------------------------------------------------------------
  16.  
  17. // Tools func
  18. func void SetCaption(szx _sxTxt);
  19.  
  20. // Initializer
  21.  
  22. // Message handling interface
  23. interface Gui_iCaption
  24. {
  25.     SetCaption    Caption;
  26. }
  27.  
  28.  
  29. // Constructor
  30. func Gui_Component NewCaption(Menu_Material _pFont,szx _sxTxt)
  31. {
  32.     var Menu_Sprite sprite;
  33.     var Gui_Component caption;
  34.     var f32x w,h;
  35.  
  36.     // Create container with caption interface
  37.     caption = NewContainer(Gui_iCaption);
  38.     SetAlign(caption,e_GUI_HAlign_Left,e_GUI_VAlign_Top);
  39. //    pdtCaption.szText = _sxTxt;
  40.  
  41.     // Create a sprite with material and area index e_GUI_State_Enabled
  42.     sprite = NewSprite2D(_pFont);
  43.     w = PrecalcTextWidth(sprite,_sxTxt);
  44.     h = PrecalcTextHeight(sprite,_sxTxt);
  45.     SetText(sprite,_sxTxt);
  46.     SetShadingMode(sprite,DLC_GouraudMode_ModulateDiffuse,DLC_GouraudMode_Decal);
  47.  
  48.     // Attach the sprite to this container
  49.     AttachSprite(caption,sprite);
  50.  
  51.     // Stretch caption to fit text
  52.     StretchTo(caption,w,h);
  53.  
  54.     return caption;
  55. }
  56.  
  57. func Gui_Component NewCaptionAspectRatio(Menu_Material _pFont,szx _sxTxt, f32x _fFontSize)
  58. {
  59.     var Menu_Sprite sprite;
  60.     var Gui_Component caption;
  61.     var f32x w,h,factor;
  62.  
  63.     // Create container with caption interface
  64.     caption = NewContainer(Gui_iCaption);
  65.     SetAlign(caption,0,0);
  66.  
  67.     // Create a sprite with material and area index e_GUI_State_Enabled
  68.     sprite = NewSprite2D(_pFont);
  69.     SetText(sprite,_sxTxt);
  70.     SetShadingMode(sprite,DLC_GouraudMode_ModulateDiffuse,DLC_GouraudMode_Decal);
  71.  
  72.     // Attach the sprite to this container
  73.     AttachSprite(caption,sprite);
  74.     SetScale(caption,_fFontSize*g_fScreenScaleFactor);
  75.  
  76.     // calcul caption size
  77.     factor = (_fFontSize / 1.0); 
  78.     w = PrecalcTextWidth(sprite,_sxTxt) * factor;
  79.     h = PrecalcTextHeight(sprite,_sxTxt)* factor;
  80.  
  81.     // Stretch caption to fit text
  82.     StretchTo(caption,w,h);
  83.  
  84.     return caption;
  85. }
  86.  
  87. func void SetCaption(szx _szTxt)
  88. {
  89.     var Menu_Sprite sprite;
  90.     var Gui_Component caption;
  91.  
  92.     // Retrieve caption component
  93.     caption = GetThis();
  94.  
  95.     // Retrieve sprite
  96.     sprite = GetSprite(caption);
  97.  
  98.     // Update text
  99.     SetText(sprite,_szTxt);
  100. }
  101.  
  102.